//
//  MBSpaceSystenNewsViewController.m
//  MiBaoTu
//
//  Created by admin on 16/9/20.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSpaceSystenNewsViewController.h"

@interface MBSpaceSystenNewsViewController () {
    UIScrollView            *_scrollView;
    UILabel                 *_contentLb;
}

@end

@implementation MBSpaceSystenNewsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitleView:@"系统消息"];
    [self setBackItem];
    
    [self onCreateUI];
}

#pragma mark - Actions
#pragma mark - UI
- (void)onCreateUI
{
    if (IOS7) {
        self.automaticallyAdjustsScrollViewInsets = YES;
    }
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.view.height)];
    _scrollView.backgroundColor = [UIColor clearColor];
    _scrollView.showsHorizontalScrollIndicator = YES;
    _scrollView.showsVerticalScrollIndicator = YES;
    [self.view addSubview:_scrollView];
    
    _contentLb = [[UILabel alloc]initWithFrame:CGRectMake(25*PERCEN, 30*PERCEN, _scrollView.width-40*PERCEN, _scrollView.height)];
    _contentLb.backgroundColor = [UIColor clearColor];
    _contentLb.textAlignment = NSTextAlignmentLeft;
    _contentLb.textColor = UIColorFromHex(0x333333);
    _contentLb.font = [UIFont systemFontOfSize:13.f];
    _contentLb.numberOfLines = 0;
    [_scrollView addSubview:_contentLb];
    
    NSString *str = [NSString stringWithFormat:@"%@",[_dataDic objectForKey:@"SysContent"]];
    NSMutableParagraphStyle *mutStyle = [[NSMutableParagraphStyle alloc]init];
    mutStyle.lineSpacing = 15*PERCEN;
    
    NSMutableAttributedString *mutAttribute = [[NSMutableAttributedString alloc]initWithString:str];
    [mutAttribute addAttribute:NSFontAttributeName value:_contentLb.font range:NSMakeRange(0, str.length)];
    [mutAttribute addAttribute:NSParagraphStyleAttributeName value:mutStyle range:NSMakeRange(0, str.length)];
    float heiht = [mutAttribute boundingRectWithSize:CGSizeMake(_contentLb.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height+10;
    _contentLb.height = heiht;
    _contentLb.attributedText = mutAttribute;
    _scrollView.contentSize = CGSizeMake(_scrollView.width, (_scrollView.height >= (heiht+30)? _scrollView.height-NAV_HEIGHT : heiht+30));

}

- (void)onUpdateUIForView:(UIDeviceOrientation)orientation
{
    _scrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.view.height);
    _contentLb.frame = CGRectMake(25*PERCEN, 30*PERCEN, _scrollView.width-40*PERCEN, _scrollView.height);
    NSMutableParagraphStyle *mutStyle = [[NSMutableParagraphStyle alloc]init];
    mutStyle.lineSpacing = 15*PERCEN;
    
    NSMutableAttributedString *mutAttribute = [[NSMutableAttributedString alloc]initWithString:_contentLb.text];
    [mutAttribute addAttribute:NSFontAttributeName value:_contentLb.font range:NSMakeRange(0, _contentLb.text.length)];
    [mutAttribute addAttribute:NSParagraphStyleAttributeName value:mutStyle range:NSMakeRange(0, _contentLb.text.length)];
    float heiht = [mutAttribute boundingRectWithSize:CGSizeMake(_contentLb.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height+10;
    _contentLb.height = heiht;
    _contentLb.attributedText = mutAttribute;
    _scrollView.contentSize = CGSizeMake(_scrollView.width, (_scrollView.height >= (heiht+30)? _scrollView.height-NAV_HEIGHT : heiht+30));
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
